Skip to content

fix(bidi): Gemini 3.1 Flash Live compatibility for BidiGeminiLiveModel#2000

Open
jrdeck wants to merge 1 commit intostrands-agents:mainfrom
clevvi:fix/gemini-3.1-flash-live-compat
Open

fix(bidi): Gemini 3.1 Flash Live compatibility for BidiGeminiLiveModel#2000
jrdeck wants to merge 1 commit intostrands-agents:mainfrom
clevvi:fix/gemini-3.1-flash-live-compat

Conversation

@jrdeck
Copy link
Copy Markdown

@jrdeck jrdeck commented Mar 29, 2026

Summary

Fixes three incompatibilities that prevent BidiGeminiLiveModel from working with gemini-3.1-flash-live-preview.

Closes #1999

Changes

1. Route text input through send_realtime_input

Gemini 3.1 Flash Live only allows send_client_content for seeding initial context history. Mid-session text (e.g. BidiTextInputEvent from a BidiAgent auto-greeting) must use send_realtime_input(text=...) instead. This path is also compatible with Gemini 2.5 models — no regression.

Before: _send_text_contentsend_client_content → error 1007
After: _send_text_contentsend_realtime_input(text=...) → audio response

2. Omit session_resumption when no handle exists

_build_live_config unconditionally injected session_resumption: {"handle": None}. Gemini 3.1 rejects this; 2.5 silently accepted it. Now only included when a handle is actually provided.

3. Default api_version to v1beta

_resolve_client_config defaulted to v1alpha, which is not a documented Gemini Developer API version. Changed to v1beta — the correct endpoint for the Live API per Google's documentation.

Test plan

  • All 18 existing test_gemini_live.py tests pass
  • Test assertion updated: text input now asserts send_realtime_input(text=...) instead of send_client_content
  • Confirmed end-to-end: gemini-3.1-flash-live-preview returns audio chunks in response to text sent via send_realtime_input
  • Confirmed backward-compatible: gemini-2.5-flash-native-audio-latest works with the same code path

Context

Discovered by Clevvi while building a multi-agent voice assistant on Bedrock AgentCore + Strands. The workaround (subclassing BidiGeminiLiveModel) is deployed in production — this PR upstreams the fix.

Three fixes for Gemini 3.1 Flash Live (`gemini-3.1-flash-live-preview`):

1. Route text input through `send_realtime_input` instead of
   `send_client_content`. Gemini 3.1 only accepts `send_client_content`
   for seeding initial context history — mid-session text causes error
   1007. `send_realtime_input(text=...)` is compatible with both 2.5
   and 3.1 models.

2. Only include `session_resumption` in live config when a handle is
   provided. Sending `{"handle": null}` causes Gemini 3.1 to reject
   the session with error 1007.

3. Default `api_version` from `v1alpha` to `v1beta`. `v1alpha` is not
   a documented Gemini Developer API version; `v1beta` is the correct
   endpoint for the Live API.

Closes strands-agents#1999
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BidiGeminiLiveModel incompatible with Gemini 3.1 Flash Live

1 participant